<script type="text/javascript">
    $(document).ready(function() {
        $("#activity_checkAll").click(function() {
            if ($(this).attr("checked") == "checked") {
                $(":checkbox").attr("checked", true);
            } else {
                $(":checkbox").attr("checked", false);
            }
        });

    });
</script> 
<legend>
    <h4>
        <?php
        echo $control->getAjaxLink(array('name' => '功能列表', 'id' => 'showEventList'), array(
            'cooker' => 'BAEvent@showEventList'
        ));
        ?>\
        <?php
        echo $control->getAjaxLink(array('name' => '投票类型列表', 'id' => 'showTypeList'), array(
            'cooker' => 'BAWePollCooker@showTypeList'
        ));
        ?>\
        投票项列表
    </h4>
</legend>
<?php
$model = BAModelCooker::getDynamicModel();
$model->addField('pollAnswer');
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
$form = $this->beginWidget('CActiveForm', array(
    "id" => "manage-addRole-form",
    'enableAjaxValidation' => FALSE,
    'htmlOptions' => array('class' => '', 'role' => 'form'),
        ));
?>


<fieldset>
    <table class="table table-hover">
        <thead>
           
        </thead>
        <tbody>
            <?php
            $pollCooker = new BAWePollCooker();
            $operationName = Blyn::app()->getActiveOperation()->getName();
            foreach ($pollList as $id => $poll) {
                $question = $poll->getItem('question')->getValue();
                $pollOptionList = $pollCooker->getPollOptionList($poll);
                $modifyLink = '';
                $answerLink = '--';
                
                if ($operationName == 'admin') {
                    $modifyLink = $control->getAjaxLink('修改', array(
                        'cooker' => 'BAWePoll@showAddPoll'
                    ));
                }
                ?>
                <tr>
                    <td>问题：</td><td><?php echo $poll->getItem('question')->getValue(); ?></td><td><?php echo $modifyLink; ?></td></tr>
                <?php
                $i = 0;
                foreach ($pollOptionList as $optionId => $option) {
                    $optionText = $option->getItem('text')->getValue();
                    if ($operationName != 'admin') {
                        $answerLink = CHtml::activeCheckBox($model, "[$optionId]pollAnswer");
                    }
                    ?>
                    <tr><td>可选：<?php echo $i++; ?></td><td><?php echo $$optionText; ?></td><td><?php echo $answerLink; ?></td></tr>
                <?php } ?>
            <?php }
            ?>
        </tbody>
    </table>
    <div class="pagination">  
        <ul>  
            <li class="active">
                <a href="javascript:void()">前一页</a>    </li>  
            <li class="active">
                <a href="javascript:void()">1</a>    </li>  
            <li class="active">
                <a href="javascript:void()">后一页</a>    </li>  
        </ul>  
    </div>
    <div>
        <?php
        if ($operationName == 'admin') {
            echo $control->getAjaxLink('增加投票项', array(
                'cooker' => 'BAWePoll@addPoll',
                'htmlOptions' => array('class' => 'btn')
            ));
        } else {
            echo $control->getAjaxLink('开始投票', array(
                'cooker' => 'BAWePoll@pollNow',
                'htmlOptions' => array('class' => 'btn')
            ));
        }
        ?>
        <?php ?>
    </div>
    <?php $this->endWidget(); ?>
